﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using zdzh.zdmgr.BLL;
using zdzh.zdmgr.COL;
using zdzh.zdmgr.SFL;

namespace zdzh.zdmgr.UIL.xiaoshoup
{
    /// <summary>
    /// 对象名称：“回迁协议模块”添加信息页面（用户界面层）
    /// 对象说明：该页面用于向数据库中添加“回迁协议”对象，操作完成后返回列表页面。
    /// 作者姓名：飞翔熊
    /// 编写日期：2012/12/3 13:23:16
    /// </summary>
    public partial class Create : System.Web.UI.Page
    {
        protected Xiaoshou xiaoshou;
        protected Fangyuan fangyuan;
        protected Dingdan dingdan;
        protected Huiqianxieyi xieyi;
        protected List<Huiqianhu> huiqianhu;
        protected int index;
        
        //TextBox覆盖设置 onfocus="document.getElementById('DropDownList1').click()";

        /// <summary>
        /// “回迁协议模块”添加信息页面载入时的事件处理方法。
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            index = Convert.ToInt32(Request.QueryString["Index"]);
            fangyuan = FangyuanBLL.GetDataByIndex(index);
            huiqianhu = HuiqianhuBLL.GetDataByXieyihao(fangyuan.XieyiIndex.Value);
            if (huiqianhu == null)
                throw new CustomException("对不起，所要查询的购房人信息不存在或已删除。");
            if (fangyuan.XieyiIndex < 10000)
            {
                xieyi = HuiqianxieyiBLL.GetDataByIndex(fangyuan.XieyiIndex.Value);
                if (xieyi == null)
                    throw new CustomException("对不起，所要查询的回迁协议信息不存在或已删除。");
            }
            else
            {
                dingdan = DingdanBLL.GetDataByIndex(fangyuan.XieyiIndex.Value); // 从数据库中获取关联对象信息，以备进行修改操作。
                if (dingdan == null)
                    throw new CustomException("对不起，所要查询的订单信息不存在或已删除。");
            }

            if (!Page.IsPostBack)
            {                
                BindObjectToForm();  // 将关联对象默认值，绑定至界面控件进行显示。
                if (fangyuan.Type == 4)
                    DdlPayMode.SelectedIndex = 2;
            }
        }

        /// <summary>
        /// 用户单击“保存”按钮时的事件处理方法。
        /// </summary>
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            xiaoshou = new Xiaoshou();
            BindFormlToObject();
            XiaoshouBLL.Insert(xiaoshou);
            Main.SysMessage.ShowSuccessMsg("“员工”添加成功，单击“确定”返回信息列表。",
                "Default.aspx?RepGrid_Page=" + Int32.MaxValue.ToString()); // 添加完成后，返回列表中的最后一页。
        }

        #region 界面控件与关联对象之间的绑定方法

        /// <summary>
        /// 将界面控件中的值，绑定给关联对象。
        /// </summary>
        private void BindFormlToObject()
        {
            //yuangong.ID = DataValid.GetNullOrString(TxtID.Text);  // 协议号
            //yuangong.Name = DataValid.GetNullOrString(TxtName.Text);  // 补偿
            //yuangong.Pwd = DataValid.GetNullOrString(TxtPwd.Text);  // 差价
            //yuangong.Type = DataValid.GetNullOrInt(TxtType.Text);  // 搬家天数
        }

        /// <summary>
        /// 将关联对象中的值，绑定至界面控件进行显示。
        /// </summary>
        private void BindObjectToForm()
        {
            if (fangyuan.XieyiIndex >= 10000)
                LblNumber.Text = dingdan.Number;
            LblDate.Text = DateTime.Now.ToString("yyyy年MM月dd日");
            LblCrc.Text = "防伪校验码";
            string strOwner = "";
            foreach (Huiqianhu model in huiqianhu)
                strOwner += model.Xingming + " ";
            TxtOwner.Text = strOwner;
            LblBuild.Text = fangyuan.getBuild()+fangyuan.getType();
            LblArea.Text = fangyuan.Area.ToString()+"㎡";
        }

        #endregion 界面控件与关联对象之间的绑定方法

        protected void DdlType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DdlType.SelectedIndex == 3)
                LblShoukuanren.Visible = true;
            else
                LblShoukuanren.Visible = false;
        }

        protected void TxtMoney_TextChanged(object sender, EventArgs e)
        {

            LblMoney.Text = DataValid.ConvertToChineseMoney(Convert.ToDouble(TxtMoney.Text));
        }



    }
}
